package com.ala4.oxcafe.controller;

import com.ala4.oxcafe.boot.annotation.Permission;
import com.ala4.oxcafe.boot.page.PageDomain;
import com.ala4.oxcafe.boot.page.PageResult;
import com.ala4.oxcafe.domain.R;
import com.ala4.oxcafe.dto.OperateDTO;
import com.ala4.oxcafe.entity.StoreInfo;
import com.ala4.oxcafe.service.StoreInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 门店管理
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/14 15:11
 */
@Slf4j
@RestController
@RequestMapping("/v1/store-info")
@AllArgsConstructor
@Tag(name = "门店管理", description = "用于管理门店信息")
public class StoreInfoController {

    private final StoreInfoService storeInfoService;

    @Operation(summary = "分页查询门店信息")
    @GetMapping("/page")
//    @PreAuthorize("@preService.hasPermi('basic:corporate:list')")
    public R<PageResult<StoreInfo>> page(PageDomain pageDomain, StoreInfo storeInfo) {
        return R.ok(PageResult.iPage(storeInfoService.storeInfoPage(pageDomain, storeInfo)));
    }


    @Operation(summary = "列表查询门店信息")
    @GetMapping("/list")
    @Permission(permissionPublic = true)
    public R<List<StoreInfo>> list(StoreInfo storeInfo) {
        return R.ok(storeInfoService.storeInfoList(storeInfo));
    }

    @Operation(summary = "创建门店信息")
    @PostMapping("/create")
    public R<StoreInfo> create(@RequestBody @Validated(StoreInfo.Create.class) StoreInfo storeInfo) {
        return R.ok(storeInfoService.createStoreInfo(storeInfo));
    }

    @Operation(summary = "更新门店信息")
    @PutMapping("/update")
    public R<StoreInfo> update(@RequestBody @Validated(StoreInfo.Update.class) StoreInfo storeInfo) {
        return R.ok(storeInfoService.updateStoreInfo(storeInfo));
    }

    @Operation(summary = "门店冻结/解冻")
    @PutMapping("/freeze-thaw")
    public R<StoreInfo> freezeThaw(@RequestBody OperateDTO operateDTO) {
        return R.ok(storeInfoService.freezeThaw(operateDTO));
    }

    @Operation(summary = "删除门店信息")
    @DeleteMapping("/delete/{storeId}")
    public R<?> delete(@PathVariable Long storeId) {
        storeInfoService.deleteStoreInfo(storeId);
        return R.ok();
    }

    @Operation(summary = "门店信息详情")
    @GetMapping("/{storeId}")
    public R<StoreInfo> info(@PathVariable Long storeId) {
        return R.ok(storeInfoService.storeInfoInfo(storeId));
    }


}
